/*
  This file is part of 'Trivial chess'.

  'Trivial chess' is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  'Trivial chess' is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with 'Trivial chess'.  If not, see <http://www.gnu.org/licenses/>.
*/

/* SVN FILE: $Id$ */
/**
 * @author         $Author$
 * @version        $Rev$
 * @lastrevision   $Date$
 * @filesource     $URL$
 */


//#define BOOST_TEST_MODULE Move
#include <boost/test/unit_test.hpp>
#include "../config.h"
#include "../macros.h"


BOOST_AUTO_TEST_SUITE( MoveTest )

const Piece PROMOTED_PIECES[] = {
		Piece::NIL(),
		Piece::QUEEN(),
		Piece::ROOK(),
		Piece::KNIGHT(),
		Piece::BISHOP()
	};

const std::string MOVES[] = {
		"e2e4",
		"d7d5",
		"a7a8q",
		"h2h1r"
};

BOOST_AUTO_TEST_CASE( testFromAndToAndPromoted ) {
	Move move;

	for ( int i = 0; i < 5; ++i ) {
		move.setPromoted(PROMOTED_PIECES[i]);
		BOOST_CHECK_EQUAL(move.promoted(), PROMOTED_PIECES[i]);
		FOREACH(Square, to) {
			move.setTo(*to);
			BOOST_CHECK_EQUAL(move.to(), *to);
			BOOST_CHECK_EQUAL(move.promoted(), PROMOTED_PIECES[i]);
			FOREACH(Square, from) {
				if ( *from == *to )
					continue;
				move.setFrom(*from);
				BOOST_CHECK_EQUAL(move.from(), *from);
				BOOST_CHECK_EQUAL(move.to(), *to);
				BOOST_CHECK_EQUAL(move.promoted(), PROMOTED_PIECES[i]);
			}
		}
	}
}


BOOST_AUTO_TEST_CASE( testToStrAndFromStr ) {
	for ( int i = 0; i < 4; ++i ) {
		Move move;
		move.fromStr(MOVES[i]);
		BOOST_CHECK_EQUAL(move.toStr(), MOVES[i]);
	}
}

BOOST_AUTO_TEST_SUITE_END()
